﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.Web.Views.Master;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PolicyInjection;
using Infrastructure.Aspect.Constants;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Infrastructure.Web.Interceptor;
using Microsoft.Practices.Unity;
using Skynet.BusinessEntities;
using Skynet.WebFoundation.Services.Session;
using System.ComponentModel;
using Skynet.BusinessLogic.BusinessComponents;
using Infrastructure.Aspect.ExceptionHandling;

namespace Skynet.WebAdministracion.Views.CustomersMgm
{
    [System.ComponentModel.DataObject]
    public class CustomerMgmPresenter  :MasterPresenter<ICustomerMgmView>
    {
        [Dependency]
        public BusinessLogic.BusinessComponents.IBCCustomers BCCustomers { get; set; }

        [Dependency]
        public IBCCustomersQueries BCCustomersQueries { get; set; }

        [Dependency]
        public ISessionService SessionService { get; set; }

        public override void OnViewInitialized()
        {
            
        }
        
        [PerformanceInspectorAttribute]
        public override void OnViewLoaded()
        {
            
        }        
        
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
        public void Add(Customer item)
        {
            item.MarkAsAdded();
            item.Id = Guid.NewGuid();            
            this.BCCustomers.MaintenanceCustomers(item);            
        }
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public void Update(Customer item)
        {
            item.MarkAsModified();
            this.BCCustomers.MaintenanceCustomers(item);
            
        }        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public void Delete(Customer item)
        {
            item.MarkAsDeleted();
            this.BCCustomers.MaintenanceCustomers(item);            
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public IEnumerable<Customer> GetUsuarios()
        {
            return this.BCCustomersQueries.FindCustomers();
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public Customer GetUsuario(Guid Id)
        {
            if (Id == null || Id == Guid.Empty) return null; 
            return this.BCCustomersQueries.FindCustomers(BusinessLogic.BusinessComponents.CustomerFindOptions.GetOne, Id).SingleOrDefault();
        }        
    }
}
